package com.eos.control.action.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import com.eos.orm.mybatis.model.SysUser;
import com.hf.utils.StringUtil;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

public class IdentityInterceptor extends AbstractInterceptor {
	private static final long serialVersionUID = 7344936947760321659L;

	@Override
	public String intercept(ActionInvocation invocation) throws Exception {
		HttpServletRequest request = ServletActionContext.getRequest();
		HttpSession session = request.getSession();
		String referer = request.getHeader("referer");
		SysUser user = (SysUser) session.getAttribute("SysUser");
		if (null == user)
			return Action.LOGIN;
		if(StringUtil.isEmpty(referer))
			return Action.ERROR;
		return invocation.invoke();
	}
}
